<template>
  <page-view>
    <el-card>
      <template #header>
        <div class="font-bold">新增菜品分类</div>
      </template>
      <el-form :model="queryFormData" label-width="120px">
        <el-form-item label="分类名称">
          <el-input placeholder="请输入分类名称" v-model="queryFormData.category_name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="queryData" :loading="isLoading">
            <el-icon>
              <Search />
            </el-icon>
            保存数据
          </el-button>

          <el-button @click="resetForm" :loading="isLoading">
            重置
          </el-button>

        </el-form-item>
      </el-form>

    </el-card>
  </page-view>
</template>

<script setup>
import { reactive, ref } from "vue";
import { Search, CirclePlus } from "@element-plus/icons-vue";
import API from "@/utils/API/index.js";
import { ElNotification } from "element-plus";
import { onMounted, inject } from "vue";
import { useRouter } from "vue-router";
const baseURL = inject("baseURL");
const isLoading = ref(false);
//得到裸游管理对象
const router = useRouter();
const queryFormData = reactive({
  category_name: "",

});

const resultData = reactive({
  listData: [],
  pageCount: 0,
  totalCount: 0,
});

//新增操作
const queryData = () => {
  isLoading.value = true;
  API.categoryInfo
    .add(queryFormData)
    .then((result) => {
      //登录成功以后要跳转页面
      ElNotification({
        title: "提示",
        message: "新增成功",
        type: "success",
      });
      //跳转路由
      router.replace({
        name: "CategoryInfoList",
      });
    })
    .finally(() => {
      isLoading.value = false;
    });
};


//重置表单

const resetForm = () => {
  // console.log(formEl);
  queryFormData.category_name = null;
}




</script>

<style scoped>

</style>
